<template>
  <div>
    <a-empty v-if="org==null"></a-empty>
    <a-form v-else :labelCol="{ span: 3 }" :wrapperCol="{ span: 20 }">
      <a-form-item label="组织名称" required>
        <ZgInput v-model="org.name" :width="200"></ZgInput>
      </a-form-item>
      <a-form-item label="组织简称">
        <ZgInput v-model="org.shortName" :width="200"></ZgInput>
      </a-form-item>
      <a-form-item label="组织编码">
        <ZgInput v-model="org.code" :width="200"></ZgInput>
      </a-form-item>
      <a-form-item label="组织类型">
        <ZgDictionary v-model="org.type" code="orgType" :width="200"></ZgDictionary>
      </a-form-item>
      <a-form-item label="组织层级">
        {{ org.nameLink }}
      </a-form-item>
      <a-form-item label="描述信息">
        <a-textarea v-model="org.intro" :rows="6"></a-textarea>
      </a-form-item>
    </a-form>
    <div class="flx-c mt30">
      <ZgButton icon="save" @click="save">保存组织信息</ZgButton>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    orgId: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      org: null
    }
  },
  mounted () {
    this.search()
  },
  watch: {
    orgId () {
      this.search()
    }
  },
  methods: {
    search () {
      if (!this.orgId || this.orgId.length === 0) {
        return
      }
      this.$http.get('/zg-system/org/info', { id: this.orgId }, data => {
        this.org = data
      })
    },
    save () {
      if (this.org.name.length === 0) {
        this.$error({ title: '请设置组织名称' })
        return
      }
      this.$http.post('/zg-system/org/update', this.org, () => {
        this.$success({ title: '操作成功' })
      })
    }
  }
}
</script>
<style lang="less" scoped>
.ant-form-item{
  margin-bottom:0px;
}
</style>
